package com.lcw.lostandfound.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lcw.lostandfound.mapper.UserMapper;
import com.lcw.lostandfound.pojo.Goods;
import com.lcw.lostandfound.pojo.User;
import com.lcw.lostandfound.service.UserService;
import com.lcw.lostandfound.util.SendSMS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private SendSMS send;
    @Override
    public List<User> findAllUsers() {
        return userMapper.findAllUsers();
    }

    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    }

    @Override
    public User findByName(String username) {
        return userMapper.findByName(username);
    }

    @Override
    public int deleteByName(String username) {
        return userMapper.deleteByName(username);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public int deleteById(Integer id) {
        return userMapper.deleteById(id);
    }

    @Override
    public User doLogin(String username, String password) {
        return userMapper.doLogin(username,password);
    }

    @Override
    public User checkTel(String tel) {
        return userMapper.checkTel(tel);
    }

    @Override
    public String sendSMS(String tel) {
        System.out.println(tel);
        return send.sendSMS(tel);
    }

    @Override
    public PageInfo<User> findUser(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> allUsers = userMapper.findAllUsers();
        return new PageInfo<>(allUsers);
    }
}
